package com.platform.common.config;

import com.platform.common.interceptor.ResponseResultInterceptor;
import com.platform.common.interceptor.RoleOperationInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * describe:web配置类
 *
 * @author Administrator
 * @date 2019/12/09
 * @Time 23:53
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    /**
     * 注册拦截器
     * @param registry 拦截器注册
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //角色权限拦截器
        registry.addInterceptor(new RoleOperationInterceptor());
        //统一返回封装拦截器
        registry.addInterceptor(new ResponseResultInterceptor());
    }

    /**注册资源处理器
     * @param registry 注册资源处理器注册
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}
